<script type="text/javascript">
    // 创建相册事件
    const buttonDom = document.querySelector(".pic-upload>input[type=button]");
    
    buttonDom.onclick = function() {
        const albumName = prompt("请输入相册名字：", "");
        if (albumName) {
            // 在浏览器端增加一个相册
            const divDom = document.querySelector(".pic-collection");
            const picDom = document.querySelector(".selected");
            const index = divDom.parentNode.children.length;
            
            let newdiv = divDom.cloneNode(true);  // deep clone
            let adom = newdiv.querySelector("a");
            let buttondom = newdiv.querySelector("button");
            buttondom.name = albumName;
            adom.innerText = albumName;
            divDom.insertAdjacentElement("afterend", newdiv);

            let newpicdiv = picDom.cloneNode(false); // shallow clone
            picDom.classList.remove("selected");

            newpicdiv.dataset.name = albumName;
            picDom.insertAdjacentElement("afterend", newpicdiv);
            // 在服务器端增加一个相册文件夹
            fetch("/upload-album", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({"albumName": albumName})
            }).then(res => res.text());
        }
    }
</script>